/* eslint-disable node/prefer-global/process */
import dotenv from 'dotenv'

dotenv.config()

const config = {
  // 服务器配置
  server: {
    port: process.env.PORT || 3000,
    env: process.env.NODE_ENV || 'development',
  },

  // 数据库配置
  database: {
    development: {
      host: process.env.DB_HOST || 'localhost',
      port: process.env.DB_PORT || 3306,
      username: process.env.DB_USER || 'root',
      password: process.env.DB_PASSWORD || '',
      database: process.env.DB_NAME || 'bizhi_dev',
      dialect: 'mysql',
      timezone: '+08:00',
      logging: console.log,
    },
    test: {
      host: process.env.DB_HOST_TEST || 'localhost',
      port: process.env.DB_PORT_TEST || 3306,
      username: process.env.DB_USER_TEST || 'root',
      password: process.env.DB_PASSWORD_TEST || '',
      database: process.env.DB_NAME_TEST || 'bizhi_test',
      dialect: 'mysql',
      timezone: '+08:00',
      logging: false,
    },
    production: {
      host: process.env.DB_HOST_PROD || 'localhost',
      port: process.env.DB_PORT_PROD || 3306,
      username: process.env.DB_USER_PROD || 'root',
      password: process.env.DB_PASSWORD_PROD || '',
      database: process.env.DB_NAME_PROD || 'bizhi_prod',
      dialect: 'mysql',
      timezone: '+08:00',
      logging: false,
    },
  },

  // JWT配置
  jwt: {
    secret: process.env.JWT_SECRET || 'your-super-secret-jwt-key',
    expiresIn: process.env.JWT_EXPIRES_IN || '7d',
    adminSecret: process.env.JWT_ADMIN_SECRET || 'your-admin-secret-key',
  },

  // 短信配置
  sms: {
    provider: process.env.SMS_PROVIDER || 'aliyun', // aliyun, tencent
    accessKeyId: process.env.SMS_ACCESS_KEY_ID || '',
    accessKeySecret: process.env.SMS_ACCESS_KEY_SECRET || '',
    signName: process.env.SMS_SIGN_NAME || '彼知',
    templateCode: process.env.SMS_TEMPLATE_CODE || 'SMS_123456789',
    // 速率限制配置
    rateLimit: {
      global: 120, // 全局每分钟120次
      perIp: 3, // 单IP每分钟3次
    },
  },

  // 文件上传配置
  upload: {
    path: process.env.UPLOAD_PATH || './uploads',
    maxSize: process.env.UPLOAD_MAX_SIZE || 5 * 1024 * 1024, // 5MB
    allowedTypes: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
    // 头像图片配置
    avatar: {
      maxWidth: Number.parseInt(process.env.AVATAR_MAX_WIDTH) || 300,
      maxHeight: Number.parseInt(process.env.AVATAR_MAX_HEIGHT) || 300,
      quality: Number.parseInt(process.env.AVATAR_QUALITY) || 85,
    },
  },

  // CORS配置
  cors: {
    origin: process.env.CORS_ORIGIN || ['http://localhost:9980', 'http://localhost:9981'],
  },

  // 大模型API配置
  ai: {
    provider: process.env.AI_PROVIDER || 'openai', // openai, qianwen, etc.
    apiKey: process.env.AI_API_KEY || '',
    baseURL: process.env.AI_BASE_URL || '',
    model: process.env.AI_MODEL || 'gpt-3.5-turbo',
  },

  // 支付配置
  payment: {
    wechat: {
      appId: process.env.WECHAT_APP_ID || '',
      mchId: process.env.WECHAT_MCH_ID || '',
      key: process.env.WECHAT_KEY || '',
      notifyUrl: process.env.WECHAT_NOTIFY_URL || '',
    },
    alipay: {
      appId: process.env.ALIPAY_APP_ID || '',
      privateKey: process.env.ALIPAY_PRIVATE_KEY || '',
      publicKey: process.env.ALIPAY_PUBLIC_KEY || '',
      notifyUrl: process.env.ALIPAY_NOTIFY_URL || '',
    },
  },

  // 订单定价配置
  pricing: {
    // 基础额度单价（元）
    basePrice: Number.parseFloat(process.env.BASE_QUOTA_PRICE) || 5.0,
    // 领域额度单价（元）
    domainPrice: Number.parseFloat(process.env.DOMAIN_QUOTA_PRICE) || 8.0,
    // 专家额度使用专家自定义定价，如果专家没有设置则使用默认价格
    expertDefaultPrice: Number.parseFloat(process.env.EXPERT_DEFAULT_PRICE) || 15.0,
  },

  // 服务联动配置
  serviceIntegration: {
    // API调用超时时间（毫秒）
    timeout: Number.parseInt(process.env.SERVICE_INTEGRATION_TIMEOUT) || 30000,
    // 重试次数
    retryCount: Number.parseInt(process.env.SERVICE_INTEGRATION_RETRY_COUNT) || 3,
    // 重试间隔（毫秒）
    retryDelay: Number.parseInt(process.env.SERVICE_INTEGRATION_RETRY_DELAY) || 1000,
  },

  // 外部专家API配置（保持向后兼容）
  external: {
    expertApi: {
      baseURL: process.env.EXPERT_API_BASE_URL || '',
      apiKey: process.env.EXPERT_API_KEY || '',
    },
  },
}

export default config
